#!/usr/bin/env perl

use utf8;
use strict;
use warnings;

sub travel_dir {
	my $dir = shift;


	opendir my $dir_dh, $dir or die "Can not open dir $dir";

	{
		foreach(readdir $dir_dh){
			if($_ eq '.' || $_ eq '..'){
				next;
			}

			my $path = $dir.$_;

			my $mode = 0666;

			if(-d $path){
				$mode = 0755;
			}elsif(-x $path){
				$mode = 0777;
			}
			if(chmod $mode, $path){
				printf "chmod 0%o -----> {%s}\n", $mode, $path;
			}

			if(-d $path){
				print "find directory $path\n";
				travel_dir($path.'/');
			}
		}
	}

	closedir $dir_dh;
}

travel_dir(shift @ARGV);
